package com.ruibang.glass.quality.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.quality.domain.req.DiscardDefectReq;
import com.ruibang.glass.quality.domain.req.EveryHourDiscardDefectReq;
import com.ruibang.glass.quality.entity.EveryHourDiscardDefect;
import com.ruibang.glass.quality.mapper.EveryHourDiscardDefectMapper;
import com.ruibang.glass.quality.service.EveryHourDiscardDefectService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-08-30  11:01
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class EveryHourDiscardDefectServiceImpl extends ServiceImpl<EveryHourDiscardDefectMapper, EveryHourDiscardDefect> implements EveryHourDiscardDefectService {


    /**
     * @Description: 查询每小时判废缺陷数量及曲线
     * @version v1.0
     * @author songJinKang
     * @date 2023-08-30 11:05
     */
    @Override
    public ResultBody queryEveryHourColdDirectService(EveryHourDiscardDefectReq everyHourDiscardDefectReq) {
        List<EveryHourDiscardDefect> everyHourDiscardDefectList = baseMapper.queryEveryHourColdDirect(everyHourDiscardDefectReq);
        everyHourDiscardDefectList = everyHourDiscardDefectList.stream().sorted(Comparator.comparing(EveryHourDiscardDefect::getDiscardDate).reversed()).collect(Collectors.toList());
        return ResultBody.success(everyHourDiscardDefectList);
    }
    @Override
    public void deleteByDate(DiscardDefectReq defectReq) {
        baseMapper.deleteByDate(defectReq);
    }
    @Override
    public List<EveryHourDiscardDefect> getByTime(ArrayList<String> time) {
        QueryWrapper<EveryHourDiscardDefect> hlQw = new QueryWrapper<>();
        hlQw.lambda().in(EveryHourDiscardDefect::getDiscardDate,time);
        return this.list(hlQw);
    }
}
